﻿Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.Configuration
Imports System.Net
Public Class ProjectInstaller
    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub
    Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
        MyBase.Install(stateSaver)
        '/targetdir="[TARGETDIR]\"  /GMAIL_LOGON="[GMAIL_LOGON]"  /GMail_Password="[GMail_Password]"   /From_Keyword="[From_Keyword]"   /Program_Keyword="[Program_Keyword]"   /Polling_Interval="[Polling_Interval]"
        Dim strTargetDirectory As String = Context.Parameters("targetdir")
        Dim strGmailLogon As String = Context.Parameters("Gmail_Logon")
        Dim strGmailPassword As String = Context.Parameters("Gmail_Password")
        Dim strFrom1Keyword As String = Context.Parameters("From1_Keyword")
        Dim strFrom2Keyword As String = Context.Parameters("From2_Keyword")
        Dim strFrom3Keyword As String = Context.Parameters("From3_Keyword")
        Dim strFrom4Keyword As String = Context.Parameters("From4_Keyword")
        Dim strPrpgramKeyword As String = Context.Parameters("Program_Keyword")
        Dim strPollingInterval As String = Context.Parameters("Polling_Interval")

        If Not strGmailLogon.Contains("@") Then strGmailLogon = strGmailLogon.Trim & "@gmail.com"
        If strFrom1Keyword.Trim.Length = 0 Then strFrom1Keyword = strGmailLogon.Split("@")(0)
        If strFrom2Keyword.Trim.Length = 0 Then strFrom2Keyword = strFrom1Keyword
        If strFrom3Keyword.Trim.Length = 0 Then strFrom3Keyword = strFrom1Keyword
        If strFrom4Keyword.Trim.Length = 0 Then strFrom4Keyword = strFrom1Keyword

        Dim exePath As String = String.Format(strTargetDirectory & System.Reflection.Assembly.GetExecutingAssembly().GetName().Name & ".exe")
        Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(exePath)

        config.AppSettings.Settings("Gmail_Logon").Value = strGmailLogon
        config.AppSettings.Settings("Gmail_Password").Value = strGmailPassword
        config.AppSettings.Settings("From1_Keyword").Value = strFrom1Keyword
        config.AppSettings.Settings("From2_Keyword").Value = strFrom2Keyword
        config.AppSettings.Settings("From3_Keyword").Value = strFrom3Keyword
        config.AppSettings.Settings("From4_Keyword").Value = strFrom4Keyword
        config.AppSettings.Settings("Program_Keyword").Value = strPrpgramKeyword
        config.AppSettings.Settings("Polling_Interval").Value = strPollingInterval
        config.Save()
    End Sub

    Private Sub ProjectInstaller_BeforeInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.BeforeInstall

    End Sub
End Class
